package com.gitee.melin.bee.util;

import org.hibernate.criterion.Projection;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.criterion.Projections;

public class HibernateUtils {

    public static Projection projectionList(String... columns) {
        if (columns.length == 0) {
            return null;
        }
        ProjectionList pl = Projections.projectionList();
        for (String colName : columns) {
            pl = pl.add(Projections.property(colName).as(colName));
        }
        return pl;
    }

    public static Projection distinctProjection(String... columns) {
        if (columns.length == 0) {
            return null;
        }
        ProjectionList pl = Projections.projectionList();
        for (String colName : columns) {
            pl = pl.add(Projections.property(colName).as(colName));
        }
        return Projections.distinct(pl);
    }
}
